#include <linux/mallocator.h>

#include "tlsf.h"

static void *__tlsf_malloc(struct mallocator *m, unsigned long size, gfp_t flags)
{
    return LOS_MemAlloc(m->start, size);
}

static void __tlsf_free(struct mallocator *m, const void *object)
{
    LOS_MemFree(m->start, object);
}

static struct mallocator tlsf_allocator = {
    .alloc = __tlsf_malloc,
    .free = __tlsf_free,
};

void first_memheap_init(void *start, void *end)
{
    OsMemPoolInit(start, end - start);

    tlsf_allocator.start = start;
    tlsf_allocator.size = end - start;

    mallocator_register(&tlsf_allocator);
}
